import 'package:flutter/material.dart';
import 'Movie.dart';

List list = [
  {
    "title": "攀登者",
    "imgUrl":
        "https://p0.meituan.net/170.230/movie/4c01895cfd53e82f7c3048c407974a6b4739229.jpg"
  },
  {
    "title": "诛仙",
    "imgUrl":
        "https://p0.meituan.net/170.230/movie/845dce25ba800e91ac591b683a0c3ba92450317.jpg"
  },
  {
    "title": "小小的愿望",
    "imgUrl":
        "https://p0.meituan.net/170.230/movie/d18915868f6e3e6e287162354700690f2338229.jpg"
  },
  {
    "title": "中国机长",
    "imgUrl":
        "https://p0.meituan.net/170.230/moviemachine/4de45617746dae456738bc322670cb88562422.jpg"
  },
  {
    "title": "罗小黑战记",
    "imgUrl":
        "https://p0.meituan.net/170.230/movie/0772ff70aafc57e0005535d4d7c93b112720771.jpg"
  },
  {
    "title": "名侦探柯南",
    "imgUrl":
        "https://p0.meituan.net/170.230/moviemachine/b7362f555340906684944957dfc8d5421530646.jpg"
  },
];

class SelfListViewBuilder extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Self ListView Builder')),
      body: Container(
        padding: EdgeInsets.only(top: 100),
        height: 338,
        child: ListView.builder(
            scrollDirection: Axis.horizontal,
            itemCount: list.length,
            itemBuilder: (BuildContext context, int i) {
              var item = list[i];
              return GestureDetector(
                onTap: () {
                  Navigator.of(context)
                      .push(MaterialPageRoute(builder: (BuildContext context) {
                    return Movie(
                      title: '${item["title"]}',
                      imgUrl:
                          '${item["imgUrl"]}',
                    );
                  }));
                },
                child: Container(
                  width: 170,
                  height: 238,
                  child: Image(
                    image: NetworkImage(
                        '${item["imgUrl"]}'),
                    fit: BoxFit.cover,
                  ),
                ),
              );
            }),
      ),
    );
  }
}
